<template>
  <view>
    <view class="search-box">
    <my-search @click="gotoSearch"></my-search>
    </view>
    <!-- 轮播图的区域 -->
    <swiper indicator-dots autoplay interval="3000" :duration="1000" circular>
      <swiper-item v-for="(item, i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
<!-- 导航区域 -->
  <view class="nav-list">
   <view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
     <image :src="item.image_src"></image>
   </view> 
  </view>
  <!-- 楼层 -->
  <view class="foll-list">
    <view class="foll-item" v-for="(item,index) in floorList" :key="index">
      <image :src="item.floor_title.image_src"></image>
      <!-- 图片 -->
      <view class="floor-img-box">
        <!-- 左侧图片 -->
        <view class="left-img-box">
          <image  :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix" @click="gotoGoodsList(item.product_list[0])"></image>
        </view>
        <!-- 右侧图片 -->
        <view class="right-img-box">
          <image :src="subItem.image_src" mode="widthFix" :style="{width: subItem.image_width + 'rpx'}" v-if="subIndex>0" v-for="(subItem,subIndex) in item.product_list" :key="subIndex" @click="gotoGoodsList(subItem)"></image>
        </view>
    </view>
  </view>
  
  </view>
</view>
</template>

<script>
  export default {
    data() {
      return {
        // 这是轮播图的数据列表
        swiperList: [],
        // 分类导航的数据列表
        navList: [],
        // 楼层的数据
        floorList: []
      };
    },
    onLoad() {
      // 调用方法，获取轮播图的数据
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods: {
      gotoSearch(){
       uni.navigateTo({
         url:'/subpkg/search/search'
       })
      },
      gotoGoodsList(item){
        // console.log(item.navigator_url)
        uni.navigateTo({
          url: "/subpkg/good_list/good_list"+ item.navigator_url.substr(item.navigator_url.indexOf('?'))
        })
      },
      
      navClickHandler(item){
        if(item.name === '分类'){
          uni.switchTab({
            url:"/pages/cate/cate"
          })
        }
      },
      
      async getFloorList() {
        const { data: res } = await uni.$http.get('/api/public/v1/home/floordata')
        // 请求失败
        if (res.meta.status !== 200) return uni.$showMsg()
        this.floorList = res.message
      },
      
      async getNavList() {
        const { data: res } = await uni.$http.get('/api/public/v1/home/catitems')
        // 请求失败
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navList = res.message
      },
      
      async getSwiperList() {
        const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
        // 请求失败
        // if (res.meta.status !== 200) return uni.$showMsg()
        this.swiperList = res.message
      },
}
  }
</script>

<style lang="scss">
  .search-box{
    position: sticky;
    top: 0;
    z-index: 999;
  }
  swiper {
    height: 330rpx;

    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;
    image {
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-title {
    width: 100%;
    height: 60rpx;
  }

  .right-img-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }

  .floor-img-box {
    display: flex;
    padding-left: 10rpx;
  }
  
  .foll-item {
    image{
      height: 60rpx;
      width: 100%;
    }
  }

</style>
